---
root: "/v5.1"
description: "Swift documentation for 'ExpressibleByFloatLiteral'"
keywords: ""
title: "ExpressibleByFloatLiteral"
layout: "default"
---

<div class="intro-declaration"><code class="language-swift">protocol ExpressibleByFloatLiteral</code></div><p>A type that can be initialized with a floating-point literal.</p>
<table class="standard"><tr><th id="conforming-types">Conforming Types</th><td><code class="inherits">BinaryFloatingPoint</code></td></tr><tr><th id="associatedtypes">Associated Types</th><td><span id="aliasesmark"></span><div class="declaration"><code class="language-swift">associatedtype FloatLiteralType</code><div class="comment"><p>Valid types for <code>FloatLiteralType</code> are <code>Float</code>, <code>Double</code>, and <code>Float80</code>
where available.</p>
</div></div></td></tr></table><div class="discussion comment"><p>The standard library floating-point types---<code>Float</code>, <code>Double</code>, and
<code>Float80</code> where available---all conform to the <code>ExpressibleByFloatLiteral</code>
protocol. You can initialize a variable or constant of any of these types
by assigning a floating-point literal.</p>
<pre><code class="language-swift">// Type inferred as 'Double'
let threshold = 6.0

// An array of 'Double'
let measurements = [2.2, 4.1, 3.65, 4.2, 9.1]
</code></pre>
<h3>Conforming to ExpressibleByFloatLiteral</h3>
<p>To add <code>ExpressibleByFloatLiteral</code> conformance to your custom type,
implement the required initializer.</p>
</div><h3>Initializers</h3><div id="init_floatLiteral-8334e81b87b95183e6b6e49ec7fe203f" class="declaration"><a class="toggle-link" href="#comment-init_floatLiteral-8334e81b87b95183e6b6e49ec7fe203f">init init(floatLiteral:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init_floatLiteral-8334e81b87b95183e6b6e49ec7fe203f"><p>Creates an instance initialized to the specified floating-point value.</p>
<p>Do not call this initializer directly. Instead, initialize a variable or
constant using a floating-point literal. For example:</p>
<pre><code class="language-swift">let x = 21.5
</code></pre>
<p>In this example, the assignment to the <code>x</code> constant calls this
floating-point literal initializer behind the scenes.</p>
<ul>
<li>Parameter value: The value to create.</li>
</ul>
<h4>Declaration</h4><code class="language-swift">init(floatLiteral value: Self.FloatLiteralType)</code></div></div>